package ucd.csi.comp30220.fall2011.oteop.traffic.impl;

import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

import ucd.csi.comp30220.fall2011.oteop.collision.Collision;
import ucd.csi.comp30220.fall2011.oteop.collision.CollisionListener;
import ucd.csi.comp30220.fall2011.oteop.collision.CollisionSubscriber;
import ucd.csi.comp30220.fall2011.oteop.flight.Flight;
import ucd.csi.comp30220.fall2011.oteop.flight.FlightException;
import ucd.csi.comp30220.fall2011.oteop.flight.FlightInfo;
import ucd.csi.comp30220.fall2011.oteop.navigation.GreatCircle;
import ucd.csi.comp30220.fall2011.oteop.navigation.Position;

public class ControlTower {
	
	HashMap<String, Flight> schedule;
	List<String> airports;
	
	public ControlTower() {
	
		schedule = new HashMap<String, Flight>();
		airports = new ArrayList<String>();
	}
	
	/*
	 * Check for available airports
	 */
	
	public void addFlight(String flightNumber, Flight flight){
		schedule.put(flightNumber, flight);
		
	}
	
	public void removeFlight(String flightNumber) {
		schedule.remove(flightNumber);
	}
	
	public void alterCourse(Flight f1, Flight f2){
		try {
			if(schedule.containsValue(f1)) f1.setCourse(f1.getCourse() + 45);
			if(schedule.containsValue(f2)) f2.setCourse(f2.getCourse() - 45);
			Thread.sleep(10000);
			if(schedule.containsValue(f1)) f1.setCourse(GreatCircle.trueCourseBetween(f1.getPosition(), f1.getInfo().getDestination()));
			if(schedule.containsValue(f1)) f1.setCourse(GreatCircle.trueCourseBetween(f1.getPosition(), f1.getInfo().getDestination()));

			// NOTE: Change parameter type of setCourse() to List from []
		} catch (FlightException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public void chartCourse(Flight f, int n) throws FlightException{
		/*
		FlightInfo flightInfo = f.getInfo();
		List<Position> waypoints = GreatCircle.waypoints(flightInfo.getDeparturePoint(), flightInfo.getDestination(), n);
		Position[] c1 = (Position[]) waypoints.toArray();
		f.setRoute(c1);
		return waypoints;
		*/
	}
	
	public String printSchedule() {
		String rtn = schedule.toString();
		System.out.println(rtn);
		return rtn;
	}

}
